package core.network.client2game.handler.union;

import business.global.club.ClubMember;
import business.global.club.ClubMgr;
import business.global.union.UnionMgr;
import business.player.Player;
import com.ddm.server.common.utils.CommTime;
import com.ddm.server.websocket.def.ErrorCode;
import com.ddm.server.websocket.exception.WSException;
import com.ddm.server.websocket.handler.requset.WebSocketRequest;
import com.google.gson.Gson;
import core.network.client2game.handler.PlayerHandler;
import core.network.http.proto.SData_Result;
import jsproto.c2s.iclass.club.CClub_GameTicketChange;
import jsproto.c2s.iclass.union.CUnion_MemberExamineOperate;

import java.io.IOException;
import java.util.Objects;

/**
 * 赛事成员审核操作
 * 中至同意重赛功能
 *
 * @author zaf
 *
 */
public class CUnionMemberExamineOperateZhongZhi extends PlayerHandler {

	@SuppressWarnings("rawtypes")
	@Override
	public void handle(Player player, WebSocketRequest request, String message)
			throws WSException, IOException {
    	final CUnion_MemberExamineOperate req = new Gson().fromJson(message, CUnion_MemberExamineOperate.class);
		if(req.isClearGameTicket()){
			ClubMember doClubMember = ClubMgr.getInstance().getClubMemberMgr().getClubMember(req.getClubId(), req.getOpPid());
			if(Objects.nonNull(doClubMember)){
				ClubMgr.getInstance().getClubMemberMgr().changeGameTicketChange(new CClub_GameTicketChange(req.getClubId(),req.getOpPid(),-doClubMember.getClubMemberBO().getGameTicket(),req.getUnionId(),req.getOpClubId()),player.getPid());
			}
		}
    	SData_Result result = UnionMgr.getInstance().getUnionMemberMgr().getUnionMemberExamineOperateZhongZhi(req.getUnionId(),req.getClubId(),req.getOpPid(),req.getOpClubId(),player.getPid(),3,0);
    	if(ErrorCode.Success.equals(result.getCode())) {
			//中至重赛 另外执行一次裁定作弊
			ClubMember doClubMember = ClubMgr.getInstance().getClubMemberMgr().getClubMember(req.getClubId(), req.getOpPid());
			if(Objects.nonNull(doClubMember)){
				doClubMember.getClubMemberBO().saveLastRuleTime(CommTime.nowSecond());
			}
			request.response(result.getData());
    	} else {
    		request.error(result.getCode(), result.getMsg());
    	}
	}

}
